package jdo.crud;

import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jdo.entity.Tramway;
import jdo.pmf.PMF;

/**
 * Servlet implementation class ListServlet
 */
@SuppressWarnings("serial")
public class DeleteTramwayServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {
		PersistenceManager pm = PMF.getPersistenceManager();
		long id_tram = Long.parseLong(request.getParameter("tramwayid_tram"));
		Tramway tramway = pm.getObjectById(Tramway.class, id_tram);
		String resultat;
		if (tramway != null) {
			pm.deletePersistent(tramway);
			resultat = "deletedOK";
		} else {
			resultat = "alreadyDeleted";
		}
		pm.close();
		response.sendRedirect("/administration.jsp?message="+resultat);
	}

}
